home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / exampleCode / games / IndiZone / gold / doerClass.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  14.8 KB  |  598 lines

  1. /*
  2.  * The original copyright owners of the accompanying source code files have
  3.  * agreed to place such code into the public domain.  Accordingly, anyone
  4.  * who receives or obtains a copy of such source code is freely entitled to
  5.  * reproduce, use and otherwise exploit such code (including the right to
  6.  * make derivative works), at his/her own risk and expense, without any
  7.  * obligation or liability to the original copyright owners.
  8.  *
  9.  * We would appreciate (but do not require) that the following message be
  10.  * included in any derivative works:
  11.  *
  12.  * "Portions of this program were developed by Peter Broadwell, Rob Myers
  13.  * and Robin Schaufler while working in Silicon Valley."
  14.  *
  15.  * The accompanying source code files and related documentation materials
  16.  * are distributed on an "AS IS" basis, without any warranties or
  17.  * guarantees of any kind.  All implied warranties, including the implied
  18.  * warranties of merchantability and of fitness for any particular purpose,
  19.  * are expressly disclaimed.
  20.  */
  21. #include "gl.h"
  22. #include "geom.h"
  23. #include "selectors.h"
  24. #include "class.h"
  25. #include "classIds.h"
  26. #include "mbox.h"
  27. #include "behavior.h"
  28. #include "individual.h"
  29. #include "doers.h"
  30.  
  31. extern class behaveClass;
  32. extern char *wigglerBub;
  33. extern char *feederBub;
  34. extern char *colorizerBub;
  35. extern char *femaleBub;
  36. extern char *maleBub;
  37.  
  38. extern char *wiggle();
  39. extern char *advanceTo();
  40. extern char *swimTo();
  41. extern char *influ();
  42. extern char *altercolor();
  43. extern char *exportcolor();
  44. extern char *altershape();
  45. extern char *freeMetaVars();
  46. extern char *feed();
  47. extern char *wideneye();
  48. extern char *editFeeder();
  49. extern char *editMale();
  50. extern char *editFemale();
  51. extern char *editWiggler();
  52. extern char *editColorizer();
  53.  
  54. fcnTable wiggleTable[] = {
  55.     DOIT,    wiggle,        /* wiggle my head and tail*/
  56.     ADDPANEL,    editWiggler,
  57.     EOTABLE,
  58. };
  59.  
  60. class wigglerClass = {
  61.     &behaveClass,
  62.     wiggleTable,
  63.     sizeof(wiggler),
  64.     WIGGLER,
  65. };
  66.  
  67. wigglerVars wigglerVarTemplate = {
  68.             /*   subscr        */
  69.     NULL,        /* next subscriber      */
  70.     NULL,        /* member pointer       */
  71.             /*   wiggler        */
  72.     0,            /* angle        */
  73.     90,            /* magnitude        */
  74.     0,            /* wiggleClock        */
  75. };
  76.  
  77. wiggler wigglerTemplate = {
  78.             /*   inst        */
  79.     &wigglerClass,    /* myClass pointer    */
  80.     NULL,        /* classFunctions     */
  81.     0,            /* nFunctions        */
  82.             /*   mailbox        */
  83.     NULL,        /* subscribers          */
  84.     NULL,        /* subscribedTo         */
  85.             /*   behavior            */
  86.     sizeof(wigglerVars),          /* size of template for */
  87.     (char *)&wigglerVarTemplate,  /* instance variables   */
  88.     (char *)&wigglerBub,        /* symbolic bubble      */
  89.             /*   wiggler            */
  90.     10,            /* offsetFactor         */
  91. };
  92.  
  93. fcnTable swerveTable[] = {
  94.     DOIT,    swimTo,    /* advance to next spot along my path */
  95.     EOTABLE,
  96. };
  97.  
  98. class swerverClass = {
  99.     &behaveClass,
  100.     swerveTable,
  101.     sizeof(behavior),
  102.     SWERVER,
  103. };
  104.  
  105. swerverVars swerverVarTemplate = {
  106.             /*   subscr        */
  107.     NULL,        /* next subscriber      */
  108.     NULL,        /* member pointer       */
  109.             /*   swerver        */
  110.     {80,80,80},    /* stake        */
  111. };
  112.  
  113. behavior swerverTemplate = {
  114.             /*   inst        */
  115.     &swerverClass,    /* myClass pointer    */
  116.     NULL,        /* classFunctions     */
  117.     0,            /* nFunctions        */
  118.             /*   mailbox        */
  119.     NULL,        /* subscribers          */
  120.     NULL,        /* subscribedTo         */
  121.             /*   behavior            */
  122.     sizeof(swerverVars),     /* size of template for */
  123.     (char *)&swerverVarTemplate,  /* instance variables   */
  124.     NULL,                /* symbolic bubble      */
  125. };
  126.  
  127. fcnTable circleTable[] = {
  128.     DOIT,    advanceTo,    /* advance to next spot along my circle */
  129.     EOTABLE,
  130. };
  131.  
  132. class circlerClass = {
  133.     &behaveClass,
  134.     circleTable,
  135.     sizeof(behavior),
  136.     CIRCLER,
  137. };
  138.  
  139. circlerVars circlerVarTemplate = {
  140.             /*   subscr        */
  141.     NULL,        /* next subscriber      */
  142.     NULL,        /* member pointer       */
  143.             /*   circler        */
  144.     {100,100,1000},    /* stake        */
  145.     10000,        /* tether        */
  146.     0,            /* circleClock        */
  147.     0,            /* circleIncr         */
  148. };
  149.  
  150. behavior circlerTemplate = {
  151.             /*   inst        */
  152.     &circlerClass,    /* myClass pointer    */
  153.     NULL,        /* classFunctions     */
  154.     0,            /* nFunctions        */
  155.             /*   mailbox        */
  156.     NULL,        /* subscribers          */
  157.     NULL,        /* subscribedTo         */
  158.             /*   behavior            */
  159.     sizeof(circlerVars),          /* size of template for */
  160.     (char *)&circlerVarTemplate,  /* instance variables   */
  161.     NULL,                /* symbolic bubble      */
  162. };
  163.  
  164. fcnTable chameleonTable[] = {
  165.     DOIT,    altercolor,        /* listen to colors from outer space */
  166.     EOTABLE,
  167. };
  168.  
  169. class chameleonClass = {
  170.     &behaveClass,
  171.     chameleonTable,
  172.     sizeof(behavior),
  173.     CHAMELEON,
  174. };
  175.  
  176. chameleonVars chameleonVarTemplate = {
  177.             /*   subscr        */
  178.     NULL,        /* next subscriber      */
  179.     NULL,        /* member pointer       */
  180.             /*   chameleon        */
  181.     FALSE,        /* inited               */
  182.     FALSE,        /* influenced           */
  183.     {0,0,0},        /* nativeColor        */
  184.     {0,0,0},        /* importColor        */
  185. };
  186.  
  187. behavior chameleonTemplate = {
  188.             /*   inst        */
  189.     &chameleonClass,    /* myClass pointer    */
  190.     NULL,        /* classFunctions     */
  191.     0,            /* nFunctions        */
  192.             /*   mailbox        */
  193.     NULL,        /* subscribers          */
  194.     NULL,        /* subscribedTo         */
  195.             /*   behavior            */
  196.     sizeof(chameleonVars),          /* size of template for */
  197.     (char *)&chameleonVarTemplate,  /* instance variables   */
  198.     NULL,                  /* symbolic bubble      */
  199. };
  200.  
  201. fcnTable colorizerTable[] = {
  202.     DOIT,    exportcolor,    /* export color influence to neighbors */
  203.     ADDPANEL,    editColorizer,
  204.     EOTABLE,
  205. };
  206.  
  207. class colorizerClass = {
  208.     &behaveClass,
  209.     colorizerTable,
  210.     sizeof(behavior),
  211.     COLORIZER,
  212. };
  213.  
  214. colorizerVars colorizerVarTemplate = {
  215.             /*   subscr        */
  216.     NULL,        /* next subscriber      */
  217.     NULL,        /* member pointer       */
  218.             /*   colorizer        */
  219.     {255,255,0},        /* exportColor        */
  220. };
  221.  
  222. behavior colorizerTemplate = {
  223.             /*   inst        */
  224.     &colorizerClass,    /* myClass pointer    */
  225.     NULL,        /* classFunctions     */
  226.     0,            /* nFunctions        */
  227.             /*   mailbox        */
  228.     NULL,        /* subscribers          */
  229.     NULL,        /* subscribedTo         */
  230.             /*   behavior            */
  231.     sizeof(colorizerVars),          /* size of template for */
  232.     (char *)&colorizerVarTemplate,  /* instance variables   */
  233.     (char *)&colorizerBub,          /* symbolic bubble      */
  234. };
  235.  
  236. extern char *advance();
  237.  
  238. fcnTable advancerTable[] = {
  239.     DOIT,    advance,    /* advance by velocity by acceleration */
  240.     EOTABLE,
  241. };
  242.  
  243. class advancerClass = {
  244.     &behaveClass,
  245.     advancerTable,
  246.     sizeof(behavior),
  247.     ADVANCER,
  248. };
  249.  
  250. behavior advancerTemplate = {
  251.             /*   inst        */
  252.     &advancerClass,    /* myClass pointer    */
  253.     NULL,        /* classFunctions     */
  254.     0,            /* nFunctions        */
  255.             /*   mailbox        */
  256.     NULL,        /* subscribers          */
  257.     NULL,        /* subscribedTo         */
  258.             /*   behavior            */
  259.     sizeof(subscr),     /* size of template for */
  260.     NULL,          /* instance variables   */
  261.     NULL,          /* symbolic bubble     */
  262. };
  263.  
  264. extern char *dieAtSurface();
  265.  
  266. fcnTable surfDieTable[] = {
  267.     DOIT,    dieAtSurface,    /* die if height is at or above surface */
  268.     EOTABLE,
  269. };
  270.  
  271. class surfDieClass = {
  272.     &behaveClass,
  273.     surfDieTable,
  274.     sizeof(surfaceDie),
  275.     SURFACEDIE,
  276. };
  277.  
  278. surfaceDie surfDieTemplate = {
  279.             /*   inst        */
  280.     &surfDieClass,    /* myClass pointer    */
  281.     NULL,        /* classFunctions     */
  282.     0,            /* nFunctions        */
  283.             /*   mailbox        */
  284.     NULL,        /* subscribers          */
  285.     NULL,        /* subscribedTo         */
  286.             /*   behavior            */
  287.     sizeof(subscr),     /* size of template for */
  288.     NULL,          /* instance variables   */
  289.     NULL,          /* symbolic bubble      */
  290.             /*   surfaceDie         */
  291.     5000,        /* surface              */
  292. };
  293.  
  294. extern char *expandScale();
  295.  
  296. fcnTable expanderTable[] = {
  297.     DOIT,    expandScale,    /* increase in size up to a limit */
  298.     EOTABLE,
  299. };
  300.  
  301. class expanderClass = {
  302.     &behaveClass,
  303.     expanderTable,
  304.     sizeof(behavior),
  305.     EXPANDER,
  306. };
  307.  
  308. expanderVars expanderVarTemplate = {
  309.             /*   subscr        */
  310.     NULL,        /* next subscriber      */
  311.     NULL,        /* member pointer       */
  312.             /*   expander         */
  313.     1.0,        /* scaleMax        */
  314.     1.3,        /* scaleIncr        */
  315. };
  316.  
  317. behavior expanderTemplate = {
  318.             /*   inst        */
  319.     &expanderClass,    /* myClass pointer    */
  320.     NULL,        /* classFunctions     */
  321.     0,            /* nFunctions        */
  322.             /*   mailbox        */
  323.     NULL,        /* subscribers          */
  324.     NULL,        /* subscribedTo         */
  325.             /*   behavior            */
  326.     sizeof(expanderVars),          /* size of template for */
  327.     (char *)&expanderVarTemplate,  /* instance variables   */
  328.     NULL,                 /* symbolic bubble      */
  329. };
  330.  
  331. extern char *fadeOut();
  332.  
  333. fcnTable faderTable[] = {
  334.     DOIT,    fadeOut,    /* fade out of existence          */
  335.     EOTABLE,
  336. };
  337.  
  338. class faderClass = {
  339.     &behaveClass,
  340.     faderTable,
  341.     sizeof(behavior),
  342.     FADER,
  343. };
  344.  
  345. faderVars faderVarTemplate = {
  346.             /*   subscr        */
  347.     NULL,        /* next subscriber      */
  348.     NULL,        /* member pointer       */
  349.             /*   fader            */
  350.     16,            /* lifeSpan in tics     */
  351.     16,            /* age in tics         */
  352. };
  353.  
  354. behavior faderTemplate = {
  355.             /*   inst        */
  356.     &faderClass,    /* myClass pointer    */
  357.     NULL,        /* classFunctions     */
  358.     0,            /* nFunctions        */
  359.             /*   mailbox        */
  360.     NULL,        /* subscribers          */
  361.     NULL,        /* subscribedTo         */
  362.             /*   behavior            */
  363.     sizeof(faderVars),          /* size of template for */
  364.     (char *)&faderVarTemplate,  /* instance variables   */
  365.     NULL,              /* symbolic bubble      */
  366. };
  367.  
  368. extern char *trailGhosts();
  369.  
  370. fcnTable trailGhostTable[] = {
  371.     DOIT,    trailGhosts,    /* fade out of existence          */
  372.     EOTABLE,
  373. };
  374.  
  375. class trailGhostClass = {
  376.     &behaveClass,
  377.     trailGhostTable,
  378.     sizeof(behavior),
  379.     TRAIL_GHOSTS,
  380. };
  381.  
  382. trailGhostVars trailGhostVarTemplate = {
  383.             /*   subscr        */
  384.     NULL,        /* next subscriber      */
  385.     NULL,        /* member pointer       */
  386.             /*   fader            */
  387.     4,            /* frequency in tics     */
  388.     0,            /* tic mod frequency    */
  389. };
  390.  
  391. behavior trailGhostTemplate = {
  392.             /*   inst        */
  393.     &trailGhostClass,    /* myClass pointer    */
  394.     NULL,        /* classFunctions     */
  395.     0,            /* nFunctions        */
  396.             /*   mailbox        */
  397.     NULL,        /* subscribers          */
  398.     NULL,        /* subscribedTo         */
  399.             /*   behavior            */
  400.     sizeof(trailGhostVars),          /* size of template for */
  401.     (char *)&trailGhostVarTemplate,  /* instance variables   */
  402.     NULL,                   /* symbolic bubble      */
  403. };
  404.  
  405. extern char *lay(), *fertilize();
  406.  
  407. fcnTable femaleTable[] = {
  408.     DOIT,    lay,    /* if a male is nearby, lay eggs */
  409.     ADDPANEL,    editFemale,
  410.     EOTABLE,
  411. };
  412.  
  413. class femaleClass = {
  414.     &behaveClass,
  415.     femaleTable,
  416.     sizeof(behavior),
  417.     FEMALE,
  418. };
  419.  
  420. femaleVars femaleVarTemplate = {
  421.             /*   subscr        */
  422.     NULL,        /* next subscriber      */
  423.     NULL,        /* member pointer       */
  424.             /*   femaleVars     */
  425.     2,            /* n_girls        */
  426.     1,            /* n_boys        */
  427.     4,            /* max_population    */
  428.     NULL,        /* mate            */
  429. };
  430.  
  431. behavior femaleTemplate = {
  432.             /*   inst        */
  433.     &femaleClass,    /* myClass pointer    */
  434.     NULL,        /* classFunctions     */
  435.     0,            /* nFunctions        */
  436.             /*   mailbox        */
  437.     NULL,        /* subscribers          */
  438.     NULL,        /* subscribedTo         */
  439.             /*   behavior            */
  440.     sizeof(femaleVars), /* size of template for */
  441.     (char *)&femaleVarTemplate,      /* instance variables   */
  442.     (char *)&femaleBub,              /* symbolic bubble      */
  443. };
  444.  
  445. fcnTable maleTable[] = {
  446.     DOIT,    fertilize,    /* if a female is nearby, fertilize eggs */
  447.     ADDPANEL,    editMale,
  448.     EOTABLE,
  449. };
  450.  
  451. class maleClass = {
  452.     &behaveClass,
  453.     maleTable,
  454.     sizeof(behavior),
  455.     MALE,
  456. };
  457.  
  458. maleVars maleVarTemplate = {
  459.             /*   subscr        */
  460.     NULL,        /* next subscriber      */
  461.     NULL,        /* member pointer       */
  462.             /*   maleVars         */
  463.     -4,            /* interest            */
  464.     30,            /* rate            */
  465.     0,            /* tics            */
  466.     -4,            /* min_int            */
  467.     6,            /* max_int            */
  468.     2.0,        /* eyescale        */
  469.     0,            /* flags            */
  470. };
  471.  
  472. behavior maleTemplate = {
  473.             /*   inst        */
  474.     &maleClass,        /* myClass pointer    */
  475.     NULL,        /* classFunctions     */
  476.     0,            /* nFunctions        */
  477.             /*   mailbox        */
  478.     NULL,        /* subscribers          */
  479.     NULL,        /* subscribedTo         */
  480.             /*   behavior            */
  481.     sizeof(maleVars),   /* size of template for */
  482.     (char *)&maleVarTemplate,      /* instance variables   */
  483.     (char *)&maleBub,              /* symbolic bubble      */
  484. };
  485.  
  486. fcnTable metamorphTable[] = {
  487.     DOIT,    altershape,        /* when alarm goes off, change shape */
  488.     EOTABLE,
  489. };
  490.  
  491. class metamorphClass = {
  492.     &behaveClass,
  493.     metamorphTable,
  494.     sizeof(behavior),
  495.     METAMORPH,
  496. };
  497.  
  498. metamorphVars metamorphVarTemplate = {
  499.             /*   subscr        */
  500.     NULL,        /* next subscriber      */
  501.     NULL,        /* member pointer       */
  502.             /*   metamorph        */
  503.     0,            /* clock          */
  504.     100,        /* alarm          */
  505.     NULL,        /* embryo               */
  506. };
  507.  
  508. behavior metamorphTemplate = {
  509.             /*   inst        */
  510.     &metamorphClass,    /* myClass pointer    */
  511.     NULL,        /* classFunctions     */
  512.     0,            /* nFunctions        */
  513.             /*   mailbox        */
  514.     NULL,        /* subscribers          */
  515.     NULL,        /* subscribedTo         */
  516.             /*   behavior            */
  517.     sizeof(metamorphVars),          /* size of template for */
  518.     (char *)&metamorphVarTemplate,  /* instance variables   */
  519.     NULL,                  /* symbolic bubble      */
  520. };
  521.  
  522. fcnTable dinnerTable[] = {
  523.     DOIT,    feed,        /* when alarm goes off, change shape */
  524.     ADDPANEL,    editFeeder,    /* edit vars associated with feeder  */
  525.     EOTABLE,
  526. };
  527.  
  528. class feederClass = {
  529.     &behaveClass,
  530.     dinnerTable,
  531.     sizeof(behavior),
  532.     FEEDER,
  533. };
  534.  
  535. feederVars feederVarTemplate = {
  536.             /*   subscr        */
  537.     NULL,        /* next subscriber      */
  538.     NULL,        /* member pointer       */
  539.             /*   metamorph        */
  540.     -6,            /* interest        */
  541.     100,        /* rate            */
  542.     0,            /* tics            */
  543.     -6,            /* min_int        */
  544.     6,            /* max_int        */
  545.     FALSE,        /* cannibal        */
  546.     50.0,        /* bubscale        */
  547. };
  548.  
  549. behavior feederTemplate = {
  550.             /*   inst        */
  551.     &feederClass,    /* myClass pointer    */
  552.     NULL,        /* classFunctions     */
  553.     0,            /* nFunctions        */
  554.             /*   mailbox        */
  555.     NULL,        /* subscribers          */
  556.     NULL,        /* subscribedTo         */
  557.             /*   behavior            */
  558.     sizeof(feederVars),          /* size of template for */
  559.     (char *)&feederVarTemplate,  /* instance variables   */
  560.     (char *)&feederBub,       /* symbolic bubble      */
  561. };
  562.  
  563. fcnTable wideyeTable[] = {
  564.     DOIT,    wideneye,        /* listen to colors from outer space */
  565.     EOTABLE,
  566. };
  567.  
  568. class wideyeClass = {
  569.     &behaveClass,
  570.     wideyeTable,
  571.     sizeof(behavior),
  572.     WIDEYE,
  573. };
  574.  
  575. wideyeVars wideyeVarTemplate = {
  576.             /*   subscr        */
  577.     NULL,        /* next subscriber      */
  578.     NULL,        /* member pointer       */
  579.             /*   wideye        */
  580.     FALSE,        /* inited               */
  581.     FALSE,        /* influenced           */
  582.     2.0,        /* scalefactor        */
  583. };
  584.  
  585. behavior wideyeTemplate = {
  586.             /*   inst        */
  587.     &wideyeClass,    /* myClass pointer    */
  588.     NULL,        /* classFunctions     */
  589.     0,            /* nFunctions        */
  590.             /*   mailbox        */
  591.     NULL,        /* subscribers          */
  592.     NULL,        /* subscribedTo         */
  593.             /*   behavior            */
  594.     sizeof(wideyeVars),          /* size of template for */
  595.     (char *)&wideyeVarTemplate,  /* instance variables   */
  596.     NULL,               /* symbolic bubble      */
  597. };
  598.